//
//  CommentEntity.m
//  ybzj
//
//  Created by liyuan on 15/7/26.
//  Copyright (c) 2015年 liyuan. All rights reserved.
#import "CommentEntity.h"
#import <CoreText/CoreText.h>


@implementation CommentEntity
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

//-(void)awakeFromNib{

//}

-(id)initWithCoder:(NSCoder *)aDecoder{
    self=[super initWithCoder:aDecoder];
    if(self){
     //   CGFloat width=[UIScreen mainScreen].bounds.size.width;
        //CGFloat width=self.bounds.size.width;
        //CGFloat height=self.bounds.size.height;
        //self.GrayView.translatesAutoresizingMaskIntoConstraints=NO;
        //self.GrayView.frame=CGRectMake(width*130/400, height*11/26, width/2, height*4/26);
       
        
        
        
        
        
    }
    return self;
}

-(void)setScore:(CGFloat)score{
    CGFloat width=[UIScreen mainScreen].bounds.size.width;
    self.OrangeView.translatesAutoresizingMaskIntoConstraints=NO;
    
    NSLayoutConstraint *leftConstrainforOrangeView=[NSLayoutConstraint constraintWithItem:self.OrangeView
                                                                                attribute:NSLayoutAttributeLeading
                                                                                relatedBy:NSLayoutRelationEqual
                                                                                   toItem:self.TitleLabel
                                                                                attribute:NSLayoutAttributeTrailing
                                                                               multiplier:1.0f
                                                                                 constant:width*20/640];
    NSLayoutConstraint *widthtConstrainforOrangeView=[NSLayoutConstraint constraintWithItem:self.OrangeView
                                                                                  attribute:NSLayoutAttributeWidth
                                                                                  relatedBy:NSLayoutRelationEqual
                                                                                     toItem:nil
                                                                                  attribute:NSLayoutAttributeNotAnAttribute
                                                                                 multiplier:1.0f
                                                                                   constant:width*210*score/(640*5)];
    widthtConstrainforOrangeView.active=YES;
    leftConstrainforOrangeView.active=YES;
    
    self.GrayView.translatesAutoresizingMaskIntoConstraints=NO;
    NSLayoutConstraint *leftConstrainforGrayView=[NSLayoutConstraint constraintWithItem:self.GrayView
                                                                              attribute:NSLayoutAttributeLeading
                                                                              relatedBy:NSLayoutRelationEqual
                                                                                 toItem:self.OrangeView
                                                                              attribute:NSLayoutAttributeTrailing
                                                                             multiplier:1.0f
                                                                               constant:0];
    NSLayoutConstraint *widthConstrainforGrayView=[NSLayoutConstraint constraintWithItem:self.GrayView
                                                                               attribute:NSLayoutAttributeWidth
                                                                               relatedBy:NSLayoutRelationEqual
                                                                                  toItem:nil
                                                                               attribute:NSLayoutAttributeNotAnAttribute
                                                                              multiplier:1.0f
                                                                                constant:width*210*(5-score)/(640*5)];

    leftConstrainforGrayView.active=YES;
    widthConstrainforGrayView.active=YES;
       NSMutableAttributedString *AttributedScore=[[NSMutableAttributedString alloc]  initWithString:[NSString stringWithFormat:@"%.1f%@",score,@"分"]];
    [AttributedScore addAttribute:NSForegroundColorAttributeName
                             value:[UIColor colorWithRed:178/255.0 green:178/255.0 blue:178/255.0 alpha:1] range:NSMakeRange(0, [AttributedScore length])];
    [AttributedScore addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:width*25/640] range:NSMakeRange(0, [AttributedScore length])];
    long num1=-1.0f;
    CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberCharType,&num1);
    [AttributedScore addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(0,[AttributedScore length])];

    [self.ScoreLabel setAttributedText:AttributedScore];
    
    self.GrayView.backgroundColor=[UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1];
    self.OrangeView.backgroundColor=[UIColor colorWithRed:249/255.0 green:175/255.0 blue:45/255.0 alpha:1];
    
}

-(void)setTitle:(NSString *)Title{
    CGFloat Screenwidth=[UIScreen mainScreen].bounds.size.width;
    NSMutableAttributedString *AttributedTitle=[[NSMutableAttributedString alloc]  initWithString:[NSString stringWithFormat:@"%@",Title]];
    [AttributedTitle addAttribute:NSForegroundColorAttributeName
                            value:[UIColor colorWithRed:178/255.0 green:178/255.0 blue:178/255.0 alpha:1] range:NSMakeRange(0, [AttributedTitle length])];
    [AttributedTitle addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:Screenwidth*25/640] range:NSMakeRange(0, [AttributedTitle length])];
    long num1=-1.0f;
    CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberCharType,&num1);
    [AttributedTitle addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(0,[AttributedTitle length])];
    [self.TitleLabel setAttributedText:AttributedTitle];
}


+(CommentEntity *)instanceTextView
{
    NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"CommentEntity" owner:nil options:nil];
    return [nibView objectAtIndex:0];
}



@end
